const MongoClient = require('mongodb').MongoClient;
const url = "mongodb://taosha_user:apyl8XWP6LSW4JHs@101.35.6.34:27722/taosha";

async function main() {
  const client = await MongoClient.connect(url, {useNewUrlParser: true, useUnifiedTopology: true});
  const db = client.db('taosha');


  let topics = await db.collection('topics')
    .find(
      {content: /www.zhihu.com\/zvideo/}
    )
    .toArray();


  for (let i = 0; i < topics.length; i++) {
    let topic = topics[i];
    let tags = topic.tags;
    if (!tags) {
      tags = [];
    }
    tags.push('视频');


    let boards = topic.boards;
    if (!boards) {
      boards = [];
    }
    boards.push('视频');

    let result = await db.collection('topics').updateOne({_id: topic._id}, {
      $set: {
        tags: ['视频'],
        boards: ['视频'],
        is_video: true
      },
    });
    console.log(result.result, i, topics.length);
  }

  client.close();

}

main();
